<template>
  <div id="app" v-loading.fullscreen.lock="fullscreenLoading">
    <div class="mask" v-if="visible"></div>
    <el-dialog
      title="新增任务"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
    >
      <div class="task">
        <p>
          时间：<el-input
            type="textarea"
            :rows="2"
            placeholder="请输入时间"
            v-model="task.workDate"
          >
          </el-input>
        </p>
        <p>
          工作：<el-input
            type="textarea"
            :rows="2"
            placeholder="请输入工作内容"
            v-model="task.work"
          >
          </el-input>
        </p>
        <p>
          地点：<el-input
            type="textarea"
            :rows="2"
            placeholder="请输入地点"
            v-model="task.workPlace"
          >
          </el-input>
        </p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelAddTask">取 消</el-button>
        <el-button type="primary" @click="confirmAddTask">确 定</el-button>
      </span>
    </el-dialog>
    <div class="header">
      <h3>公司领导周工作安排</h3>
      <p v-if="weekDates.length > 0" class="header-time">{{ weekDates[0] + "至" + weekDates[6] }}</p>
      <p v-else class="header-time">{{"2001至2007"}}</p>
      <el-row>
        <el-upload
          class="upload-demo"
          action="/seeyon/rest/jssdk/leaderSchedule/uploadExcel"
          :on-success="handleAvatarSuccess"
          :show-file-list="false"
        >
          <el-button size="small" type="primary" v-if="isSummary"
            >导入</el-button
          >
        </el-upload>
        <el-button type="success" @click="exportExcel" v-if="!isSummary"
          >导出</el-button
        >
        <!-- <a :href="exportHref" class="exportExcel">导出</a> -->
        <!-- <el-button type="success" @click="switchEdit">切换状态</el-button> -->
        <el-button type="success" v-if="isEidt" @click="addRowData"
          >新增行数据</el-button
        >
        <el-button type="primary" v-if="isEidt" @click="deleteRowData"
          >删除行数据</el-button
        >
      </el-row>
    </div>
    <el-popover placement="top" width="160" v-model="visible">
      <p>确定删除该任务吗？</p>
      <div style="text-align: right; margin: 0">
        <el-button size="mini" type="text" @click="visible = false"
          >取消</el-button
        >
        <el-button type="primary" size="mini" @click="deleteTask"
          >确定</el-button
        >
      </div>
    </el-popover>
    <div class="content">
      <el-table
        @cell-click="handleCellClick"
        @row-contextmenu="handleRowClick"
        v-for="(it, index) in tablesData"
        @current-change="handleCurrentChange"
        :key="index"
        :data="it"
        :cell-style="rowStyle"
        style="width: 100%"
        row-class-name="no-hover"
        ref="table"
      >
        <el-table-column align="center" type="index" label="序号" width="50">
          <template slot-scope="scope">
            <!-- 自定义序号内容 -->
            <span>{{ scope.$index + 1 + index * 3 }}</span>
          </template></el-table-column
        >
        <el-table-column align="center" prop="name" label="姓名" width="115">
          <template slot-scope="scope">
            <div class="split-cell">
              <input
                v-on:blur="saveData"
                :disabled="!isEidt"
                v-model="scope.row.name"
                :class="isEidt ? 'nameEdit' : ''"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="日期">
          <el-table-column align="center" prop="dayData" label="/" width="88">
            <template slot-scope="scope">
              <div class="split-cell cellStyle" ref="cell">
                <span>上午</span>
                <span>下午</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="monWork"
            :label="weekDates[0] + '周一'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].monWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'monWork', 0, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />
                    <input
                      v-on:blur="saveData"
                      :title="!isEidt ? item.workPlace : ''"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'monWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].monWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'monWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'monWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="tuesWork"
            :label="weekDates[1] + '周二'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].tuesWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'tuesWork', 0, i)"
                  >
                    <input
                    :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'tuesWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].tuesWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'tuesWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'tuesWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="wedWork"
            :label="weekDates[2] + '周三'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].wedWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'wedWork', 0, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'wedWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].wedWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'wedWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                    :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                    :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'wedWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="thurWork"
            :label="weekDates[3] + '周四'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].thurWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'thurWork', 0, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'thurWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].thurWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'thurWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'thurWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="friWork"
            :label="weekDates[4] + '周五'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].friWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'friWork', 0, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'friWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].friWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'friWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'friWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="satWork"
            :label="weekDates[5] + '周六'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].satWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'satWork', 0, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="$event, addTask($event, 'satWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].satWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'satWork', 1, i)"
                  >
                    <input
                      :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'satWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
          <el-table-column
            align="center"
            prop="sunWork"
            :label="weekDates[6] + '周日'"
            width="90"
          >
            <template slot-scope="scope">
              <div class="split-cell">
                <div class="morning">
                  <div
                    class="plan1"
                    v-for="(item, i) in scope.row.dayData[0].sunWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'sunWork', 0, i)"
                  >
                    <input
                    :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                    :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'sunWork', 0)"
                    >新增</span
                  >
                </div>
                <div class="afternoon">
                  <div
                    class="plan2"
                    v-for="(item, i) in scope.row.dayData[1].sunWork"
                    :key="index + i"
                    @contextmenu="handleRightClick($event, 'sunWork', 1, i)"
                  >
                    <input
                    :title="!isEidt ? item.workDate : ''"
                      v-on:blur="saveData"
                      class="when"
                      :disabled="!isEidt"
                      v-model="item.workDate"
                      type="text"
                    />
                    <input
                      :title="!isEidt ? item.work : ''"
                      v-on:blur="saveData"
                      class="what"
                      :disabled="!isEidt"
                      v-model="item.work"
                      type="text"
                    />

                    <input
                      :title="!isEidt ? item.workPlace : ''"
                      v-on:blur="saveData"
                      :class="item.workPlace==''? 'no-underLine':'where'"
                      :disabled="!isEidt"
                      v-model="item.workPlace"
                      type="text"
                    />
                  </div>
                  <span
                    class="addBtn"
                    v-if="isEidt"
                    @click="addTask($event, 'sunWork', 1)"
                    >新增</span
                  >
                </div>
              </div>
            </template></el-table-column
          >
        </el-table-column>
      </el-table>
      <div class="notes">
        <span class="sp1">备注</span>
        <el-input class="sp2"
          type="textarea"
          :rows="2"
          v-model="notes"
        >
        </el-input>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      fullscreenLoading:true,
      //备注
      notes:'',
      // 本周日期
      weekDates: [],
      // 判断是否流程表
      isSummary: false,
      // 删除任务的参数
      deleteTaskParmas: {
        rowIndex: 0,
        weekDay: "",
        dayTime: "",
        taskIndex: "",
      },
      //删除提示显隐判断
      visible: false,
      // 导出解析数据
      exportTableData: [],
      // 控件状态
      isEidt: false,
      // 新增任务参数
      addTaskParmas: {
        rowIndex: 0,
        weekDay: "",
        dayTime: 0,
      },
      checkedRow: null,
      table: [],
      //table1: [],
      // 新增弹出框
      dialogVisible: false,
      task: {
        workDate: "",
        work: "",
        workPlace: "",
      },
      // tableJson: [],
      tableJson: [
        {
          data: {
            thurDate: "2023-11-16 14:38",
            satDate: "2023-11-18 14:38",
            tuesDate: "2023-11-14 14:38",
            friDate: "2023-11-17 14:38",
            wedDate: "2023-11-15 14:38",
            monDate: "2023-11-13 14:38",
            sunDate: "2023-11-19 14:38",
          },
          leaderName: "",
          leaderWork: {
            afternoonWork: {
              monWork: [],
              thurWork: [],
              sunWork: [],
              tuesWork: [],
              satWork: [],
              friWork: [],
              wedWork: [],
            },
            morningWork: {
              monWork: [],
              thurWork: [],
              sunWork: [],
              tuesWork: [],
              satWork: [],
              friWork: [],
              wedWork: [],
            },
          },
        },
      ],
      tablesData: [],
      // 选中的当前行
      currentRow: null,
    };
  },
  created() {
    setTimeout(() => {
      this.isSummary = top.isSummary;
      this.isEidt = top.window.isEidt;
    // 进入获取控件初始数据
    if (top.window.array && JSON.parse(top.window.array).code == 200) {
      console.log("进入获取控件初始数据",JSON.parse(top.window.array));
      this.tableJson = JSON.parse(top.window.array).data;
      top.parent.controlData = this.tableJson;
      let initDate = JSON.parse(top.window.array).data[0].data;
      let exportDate = [];
      for (const key in initDate) {
        exportDate.push(initDate[key] + " 00:00:00");
      }
      if(!this.isSummary){
        let num=0
        this.tableJson.forEach((it,index)=>{
          if(it.momo.trim() !== ''){
            num++
            this.notes += `${num}、${it.momo} `;
          }
      })
      }
      else{
         this.tableJson.forEach((it,index)=>{
          this.notes += `${it.momo} `;
      })
      }
      console.log("排序前", exportDate);
      exportDate.sort(function (a, b) {
        var dateA = new Date(a);
        var dateB = new Date(b);
        return dateA - dateB;
      });
      exportDate.forEach((item) => {
        this.weekDates.push(item.split(" ")[0]);
      });
      console.log("this.weekDates", this.weekDates);
    } else {
      this.weekDates = this.getThisWeekDates();
      let date = {
            thurDate: `${this.weekDates[3]} 14:38`,
            satDate: `${this.weekDates[5]} 14:38`,
            tuesDate: `${this.weekDates[1]} 14:38`,
            friDate: `${this.weekDates[4]} 14:38`,
            wedDate:`${this.weekDates[2]} 14:38`,
            monDate: `${this.weekDates[0]} 14:38`,
            sunDate: `${this.weekDates[6]} 14:38`,
          }
      this.tableJson[0].data = date;
    }
    this.analysisData();
    this.dateSort(this.table);
    this.dataInit();
    this.setCellHeight();
    this.$nextTick(() => {
      window.parent.document.querySelector("#leaderControl").style.height =
        document.querySelector("#app").offsetHeight + 10 + "px";
      console.log(
        window.parent.document.querySelector("#leaderControl").style.height,
        document.querySelector("#app").offsetHeight
      );
    });
    this.fullscreenLoading = false
    },500);
  },
  mounted() {
    if (
      top.window.document
        .querySelector("iframe")
        .contentDocument.querySelectorAll(".cap4-headers__btn")
    ) {
      let btns = top.window.document
        .querySelector("iframe")
        .contentDocument.querySelectorAll(".cap4-headers__btn");
      btns.forEach((item, index) => {
        if (index < btns.length - 1) {
          item.addEventListener("click", () => {
            this.exportAnalysisData();
            top.parent.controlData = this.exportTableData;
            this.saveDataAfter();
          });
        }
      });
    }
    // 发送按钮监听
    if (top.window.document.querySelector("#sendId")) {
      top.window.document
        .querySelector("#sendId")
        .addEventListener("click", () => {
          this.exportAnalysisData();
          top.parent.controlData = this.exportTableData;
          this.saveDataAfter();
        });
    }
    // 提交按钮监听
    if (top.window.document.querySelector("#_dealSubmit")) {
      top.window.document
        .querySelector("#_dealSubmit")
        .addEventListener("click", () => {
          this.exportAnalysisData();
          top.parent.controlData = this.exportTableData;
          this.saveDataAfter();
        });
    }
  },
  methods: {
    hhh() {
      console.log("cs", this.table);
    },
    // 按照日期排序
    dateSort(d) {
      d.forEach((item, index) => {
        if (item.dayData[0]) {
          for (const key in item.dayData[0]) {
            if (item.dayData[0][key]) {
              item.dayData[0][key].sort(function (a, b) {
                var dateA = new Date("2022-01-01T" + a.workDate);
                var dateB = new Date("2022-01-01T" + b.workDate);
                return dateA - dateB;
              });
            }
            if (item.dayData[1][key]) {
              item.dayData[1][key].sort(function (a, b) {
                var dateA = new Date("2022-01-01T" + a.workDate);
                var dateB = new Date("2022-01-01T" + b.workDate);
                return dateA - dateB;
              });
            }
          }
        }
      });
    },
    // 点击保存给后台传数据
    saveDataAfter() {
      console.log(
        "传给后端的数据top.parent.controlData:",
        top.parent.controlData
      );
      if (top.parent.controlMark == true) {
       if(this.isSummary){
         axios
          .post(`/seeyon/leaderScheduleController.do?method=saveSchedule`, {
            data: top.parent.controlData,
            summaryId: top.summaryId,
            //测试环境
            // memberId:window.parent.csdk.core.getFormData().formmains.formmain_16363.field0001.value,
            // 正式环境
            memberId:window.parent.csdk.core.getFormData().formmains.formmain_26205.field0005.value,
            // memberId:window.parent.csdk.core.getFormData().formmains.formmain_0023.field0005.valueId
          })
          .then((res) => {
            console.log("接口返回值：", res);
          });
       }
       else{
         axios
          .post(`/seeyon/leaderScheduleController.do?method=saveSchedule`, {
            data: top.parent.controlData,
            summaryId: top.summaryId,
          })
          .then((res) => {
            console.log("接口返回值：", res);
          });
       }
      }
    },
    // 获取本周日期
    getThisWeekDates() {
      const now = new Date();
      const today = now.getDay(); // 今天是星期几，0 表示星期天，1 表示星期一，依此类推
      // 计算本周的第一天（周一）的日期
      const firstDay = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() - today + 1
      );
      // 计算本周的最后一天（周日）的日期
      const lastDay = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() + (7 - today)
      );
      const dates = [];
      // 循环从本周的第一天到最后一天，获取每一天的日期
      for (
        let date = firstDay;
        date <= lastDay;
        date.setDate(date.getDate() + 1)
      ) {
        const formattedDate = this.formatDate(date);
        dates.push(formattedDate);
      }

      return dates;
    },
    // 格式化日期为 "YYYY-MM-DD" 格式
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },
    // 输入框失去焦点保存数据
    saveData() {
      this.exportAnalysisData();
      this.dateSort(this.table);
      // 校验是否填写名字
      let hasName = true
      console.log("前端保存到浏览器数据this.exportTableData", this.exportTableData,hasName);
      this.exportTableData.forEach((item,index)=>{
        if(item.leaderName == '' && hasName ){
          hasName = false
          alert(`表格中第${index+1}条数据姓名为空，请填写！`)
        }
      })
      if(hasName){
        top.parent.controlData = this.exportTableData;
      }
    },
    // 确定删除任务
    deleteTask() {
      this.table[this.deleteTaskParmas.rowIndex].dayData[
        this.deleteTaskParmas.dayTime
      ][`${this.deleteTaskParmas.weekDay}`].splice(
        this.deleteTaskParmas.taskIndex,
        1
      );
      (this.deleteTaskParmas = {
        rowIndex: "",
        weekDay: "",
        dayTime: "",
        taskIndex: "",
      }),
      this.setCellHeight();
      this.visible = false;
    },
    // 解析后端传过来的数据
    analysisData() {
      let newTableArr = [];
      this.tableJson.forEach((item, index) => {
        let obj = {};
        obj.data = item.data;
        obj.dayData = [];
        obj.name = item.leaderName;
        let morningObj = {};
        let afternoonObj = {};
        for (const key in item.leaderWork.morningWork) {
          let dayArr = [];
          item.leaderWork.morningWork[key].forEach((its) => {
            dayArr.push(its);
          });
          morningObj[key] = dayArr;
        }
        for (const key in item.leaderWork.afternoonWork) {
          let dayArr = [];
          item.leaderWork.afternoonWork[key].forEach((its) => {
            dayArr.push(its);
          });
          afternoonObj[key] = dayArr;
        }
        obj.dayData[0] = morningObj;
        obj.dayData[1] = afternoonObj;
        newTableArr.push(obj);
      });
      this.table = newTableArr;
      // this.table1 = JSON.parse(JSON.stringify(newTableArr));
      console.log("解析后的数据this.table", this.table);
      // console.log("解析后的数据this.table1", this.table1);
    },
    // 导出功能解析数据
    exportAnalysisData() {
      this.exportTableData = [];
      this.table.forEach((item) => {
        let obj = {};
        obj.data = item.data;
        obj.leaderName = item.name;
        obj.leaderWork = {};
        obj.momo = this.notes;
        obj.leaderWork.morningWork = item.dayData[0];
        obj.leaderWork.afternoonWork = item.dayData[1];
        this.exportTableData.push(obj);
      });
    },
    // 切换控件状态
    switchEdit() {
      this.isEidt = !this.isEidt;
      console.log("切换控件状态", this.isEidt);
      this.dataInit();
      this.setCellHeight();
    },
    // 点击获取点击行数
    handleCellClick(row, column, cell, event) {
      this.addTaskParmas.rowIndex = this.table.indexOf(row);
      this.checkedRow = this.addTaskParmas.rowIndex;
      let rows = document.querySelectorAll(".el-table__row");
      console.log("选中的行数", this.checkedRow, rows);

      rows.forEach((it, index) => {
        if (index == this.checkedRow) {
          rows[this.checkedRow].style.background = "#ecf5ff";
        } else {
          rows[index].style.background = "#fff";
        }
      });
    },
    // 表格右键点击行
    handleRowClick(row, column) {
      this.deleteTaskParmas.rowIndex = this.table.indexOf(row);
      console.log("点击的行数", this.deleteTaskParmas.rowIndex);
    },
    // 当前行选择
    handleCurrentChange(val) {
      this.currentRow = val;
      console.log("当前行选择", this.currentRow);
    },
    // 删除行数据
    deleteRowData() {
      this.table.splice(this.checkedRow, 1);
      this.dataInit();
      this.$nextTick(() => {
        window.parent.document.querySelector("#leaderControl").style.height =
          document.querySelector("#app").offsetHeight + 10 + "px";
        console.log(
          window.parent.document.querySelector("#leaderControl").style.height,
          document.querySelector("#app").offsetHeight
        );
      });
      this.setCellHeight();
      this.saveData();
    },
    // 新增行数据
    addRowData() {
      let noName = false;
      this.table.forEach(item=>{
        if(item.name == "" && !noName ){
          noName = true
          return false
        }
      })
      if(noName){
        alert("请填先写已有数据姓名")
        return false
      }
      this.table.push({
        data: this.table[0].data,
        name: "",
        dayData: [
          {
            monWork: [],
            thurWork: [],
            sunWork: [],
            tuesWork: [],
            satWork: [],
            friWork: [],
            wedWork: [],
          },
          {
            monWork: [],
            thurWork: [],
            sunWork: [],
            tuesWork: [],
            satWork: [],
            friWork: [],
            wedWork: [],
          },
        ],
      });
      this.dataInit();
      this.$nextTick(() => {
        window.parent.document.querySelector("#leaderControl").style.height =
          document.querySelector("#app").offsetHeight + 10 + "px";
        console.log(
          window.parent.document.querySelector("#leaderControl").style.height,
          document.querySelector("#app").offsetHeight
        );
      });
      this.setCellHeight();
      // this.saveData();
    },
    // 取消新增
    cancelAddTask() {
      this.task = {
        workDate: "",
        work: "",
        workPlace: "",
      };
      this.dialogVisible = false;
    },
    // 确定新增
    confirmAddTask() {
      if(this.task.workDate === '' || this.task.work === ''){
        alert('请填写完整信息')
        return false
      }
      this.table[this.addTaskParmas.rowIndex].dayData[
        this.addTaskParmas.dayTime
      ][`${this.addTaskParmas.weekDay}`].push(this.task);
      this.task = {
        workDate: "",
        work: "",
        workPlace: "",
      };
      this.dateSort(this.table);
      this.setCellHeight();
      this.dialogVisible = false;
      this.saveData();
      this.$nextTick(() => {
        window.parent.document.querySelector("#leaderControl").style.height =
          document.querySelector("#app").offsetHeight + 10 + "px";
        console.log(
          window.parent.document.querySelector("#leaderControl").style.height,
          document.querySelector("#app").offsetHeight
        );
      });
    },
    // 新增任务方法 parmas1代表周几 parmas2:0代表上午 1代表下午
    addTask(event, parmas1, parmas2) {
      let noName = false;
      this.table.forEach(item=>{
        if(item.name == "" && !noName ){
          noName = true
          return false
        }
      })
      if(noName){
        alert("请填写先已有数据姓名")
        return false
      }
      console.log(event);
      this.dialogVisible = true;
      let scrollTop = this.getScrollTop()
      console.log('滚动高度：',scrollTop)
      document.querySelector(".el-dialog").style.top = scrollTop + (scrollTop / 10) + "px";
      this.addTaskParmas.dayTime = parmas2;
      this.addTaskParmas.weekDay = parmas1;
    },
    // 获取滚动高度
    getScrollTop() {
        var iframe = null
        if(top.window.document.querySelector('#zwIframe')){
          iframe = top.window.document.querySelector('#zwIframe')
        }
        if(top.window.document.querySelector('#cap4FormContent')){
          iframe = top.window.document.querySelector('#cap4FormContent')
        }
        var iframeWindow = iframe.contentWindow;
        var iframeDocument = iframeWindow.document;
        var scrollHeight = iframeDocument.documentElement.scrollTop || iframeDocument.body.scrollTop;
        return scrollHeight;
    },
    // 关闭新增弹出框
    handleClose(done) {
      console.log("关闭新增弹出框");
      this.task = {
        workDate: "",
        work: "",
        workPlace: "",
      };
      this.dialogVisible = false;
      // this.$confirm("确认关闭？")
      //   .then((_) => {
      //     done();
      //     this.task = {
      //       workDate: "",
      //       work: "",
      //       workPlace: "",
      //     };
      //   })
      //   .catch((_) => {});
    },
    // 设置单元格高度
    setCellHeight() {
      this.$nextTick(() => {
        const cells = document.querySelectorAll(".cellStyle");
        const trs = document.querySelectorAll(".el-table__row");
        trs.forEach((it, index) => {
          // 每行上午的最大高度
          let morningHeight = 0;
          // 每行下午的最大高度
          let afterNoonHeight = 0;
          // 找到上午最大高度
          it.querySelectorAll(".morning").forEach((item, index) => {
            if (item.clientHeight > morningHeight) {
              morningHeight = item.clientHeight;
            }
          });
          // 找到下午最大高度
          it.querySelectorAll(".afternoon").forEach((item) => {
            if (item.clientHeight > afterNoonHeight) {
              afterNoonHeight = item.clientHeight;
            }
          });
          // 赋值上午高度
          it.querySelectorAll(".morning").forEach((item) => {
            item.style.minHeight = `${morningHeight}px`;
          });
          // 赋值下午高度
          it.querySelectorAll(".afternoon").forEach((item) => {
            item.style.minHeight = `${afterNoonHeight}px`;
          });
          cells[index].querySelectorAll(
            "span"
          )[0].style.minHeight = `${morningHeight}px`;
          cells[index].querySelectorAll(
            "span"
          )[1].style.minHeight = `${afterNoonHeight}px`;
        });
      });
    },

    handleAvatarSuccess(res) {
      console.log(res);
      // this.tableJson = res
      if (res.code == 200) {
        this.tableJson = res.data;
        this.weekDates = [];
        // 导入文件日期
        let exportDate = [];
        for (const key in res.data[0].data) {
          exportDate.push(res.data[0].data[key]);
        }
        // 备份赋值
        this.notes = res.data[0].momo;
        console.log("排序前", exportDate);
        exportDate.sort(function (a, b) {
          var dateA = new Date(a);
          var dateB = new Date(b);
          return dateA - dateB;
        });
        exportDate.forEach((item) => {
          this.weekDates.push(item.split(" ")[0]);
        });
        console.log("this.weekDates", this.weekDates);
      }
      top.parent.controlData = res.data;
      this.analysisData();
      console.log(this.table);
      this.dataInit();
      this.setCellHeight();
      this.$nextTick(() => {
        window.parent.document.querySelector("#leaderControl").style.height =
          document.querySelector("#app").offsetHeight + 10 + "px";
        console.log(
          window.parent.document.querySelector("#leaderControl").style.height,
          document.querySelector("#app").offsetHeight
        );
      });
    },
    // 鼠标右键点击
    handleRightClick(event, parmas1, parmas2, parmas3) {
      console.log("控件是否可编辑", this.isEidt);
      console.log("event", event);
      if (this.isEidt == false) {
        return;
      }
      event.preventDefault(); // 阻止浏览器默认行为
      this.deleteTaskParmas.weekDay = parmas1;
      this.deleteTaskParmas.dayTime = parmas2;
      this.deleteTaskParmas.taskIndex = parmas3;
      this.visible = true;
      document.querySelector(".el-popover").style.left = event.x + "px";
      document.querySelector(".el-popover").style.top = event.y + Math.floor(event.y / 10) + "px";
      console.log("右键点击", this.deleteTaskParmas);
    },
    //导入excel表格

    importExcel() {},
    //导出excel表格
    exportExcel() {
      this.exportAnalysisData();
      // if (JSON.stringify(this.table1) === JSON.stringify(this.table)) {
      window.open(
        `/seeyon/leaderScheduleController.do?method=exportSchedule&todayDate=${this.weekDates[0]}`,
        "_self"
      );
      // } else {
      //   this.$message("您已修改数据，请先保存！");
      // }
      // 发起POST请求
      // window.open(`/seeyon/leaderScheduleController.do?method=exportSchedule${top.window.location.href.split()}`,'_self')
    },
    // 初始化数据处理
    dataInit() {
      this.tablesData = this.splitTable(this.table, 3);
    },
    // 分割初始化数组
    splitTable(array, size) {
      const result = [];
      for (let i = 0; i < array.length; i += size) {
        const chunk = array.slice(i, i + size);
        result.push(chunk);
      }
      return result;
    },
    // 内容居中方法
    rowStyle() {
      return "text-align:center";
    },
  },
};
</script>

<style>
@import "./style/index.css";
</style>
<style lang="less" scoped>
/deep/.el-popover {
  position: fixed;
}
/deep/.el-dialog {
  margin-top: 0px !important;
  // position: fixed !important;
  // left: 50% !important;
  // transform: translate(-50%) !important;
}
// 姓名列给padding
/deep/.el-table tbody .el-table__row .el-table__cell:nth-child(2){
  padding: 0 5px !important;
  box-sizing: border-box;
}
/deep/.el-table tbody .el-table__row .el-table__cell:nth-child(2) input{
  padding: 0 5px !important;
  box-sizing: border-box;
  border: none;
}
// 表体单元格样式
/deep/.el-table tbody .el-table__row .el-table__cell{
  padding: 0px !important;
  // padding: 0px 10px !important;
}
/deep/.el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
  background-color: #fff !important;
}
/deep/.el-table .cell {
  padding: 0px !important;
}
/deep/.el-table thead.is-group th.el-table__cell {
  background-color: #fff;
}
/deep/.el-textarea {
  height: 40px;
  width: 80%;
  margin-left: 10px;
}
.nameEdit{
  background-color: #f4eeee;
}
// .exportExcel {
//   font-size: 14px;
//   background-color: #67c23a;
//   padding: 5px 10px !important;
//   border-radius: 4px;
//   margin: 10px;
//   display: inline-block;
//   line-height: 16px;
//   color: #fff;
// }
.mask {
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0);
  position: fixed;
  z-index: 999;
}
.morning {
  border-bottom: 1px solid #ebeef5;
  min-height: 63px;
  padding: 0px 10px !important;
}
.afternoon {
  min-height: 63px;
  padding: 0px 10px !important;
}
.task p {
  line-height: 40px;
  height: 40px;
  margin: 5px 0;
  /deep/.el-textarea {
    height: 40px;
    .el-textarea__inner {
      min-height: 0px !important;
      height: 40px;
    }
  }
}
.what,
.when,
.where {
  width: calc(100% - 1px);
  // background-color: rgba(0,0,0,0);
  border: none;
}
// .plan1:hover {
//   background-color: gray !important;
// }
// .plan2:hover {
//   background-color: gray !important;
// }
.addBtn {
  padding: 0px !important;
  font-size: 12px;
  line-height: 14px;
  color: skyblue;
  cursor: pointer;
}
.what {
  color: #000;
  font-size: 12px;
  font-family: "FangSongJianTi", sans-serif;
}
.when {
  color: red;
  font-size: 12px;
  font-weight: 600;
  font-family: "FangSongJianTi", sans-serif;
}
.where {
  color: #000;
  font-size: 12px;
  font-weight: 600;
  font-family: "FangSongJianTi", sans-serif;
  border-bottom: 2px solid #000;
}
.no-underLine{
  color: #000;
  font-size: 12px;
  font-weight: 600;
  font-family: "FangSongJianTi", sans-serif;
  width: calc(100% - 1px);
  border: none;
}
.split-cell {
  height: 100%;
}
.split-cell span {
  margin-bottom: 0px;
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header {
  width: 100%;
  height: 70px;
  font-size: 18px;
  text-align: center;
  margin-top: 100px;
  position: relative;
  .el-row {
    position: absolute;
    top: 40%;
    left: 0;
    .upload-demo {
      display: inline-block;
      margin-right: 10px;
      .el-upload {
        .el-button {
          font-size: 14px;
        }
      }
    }
    .el-button {
      padding: 5px 10px !important;
    }
  }
  h3 {
    line-height: 30px;
  }
  .header-time {
    line-height: 30px;
  }
}
.content {
  width: 100%;
  height: calc(100% - 170px);
  margin: 0 auto;
  .el-table {
    text-align: center;
  }
  .notes {
    height: 80px;
    width: 100%;
    border: 1px solid #ebeef5;
    border-top: none;
    display: flex;
    .sp1 {
      width: 165px;
      height: 80px;
      line-height: 80px;
      text-align: center;
      display: block;
      border-right: 1px solid #ebeef5;
    }
    .sp2 {
      flex: 1;
      height: 80px;
      line-height: 80px;
      padding-left: 10px;
      display: flex;
      justify-self: center;
      align-items: center;
      margin: 0 !important;
      padding: 0 !important;
      /deep/.el-textarea__inner{
        min-height: 76px !important;
      }
    }
  }
}
</style>
